<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="98px">
      <el-form-item label="航标名称" prop="markName">
        <el-input
          v-model="queryParams.markName"
          placeholder="请输入航标名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="所属航道" prop="channel">
        <el-input
          v-model="queryParams.channel"
          placeholder="请输入所属航道"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="岸别" prop="bankSide">
        <el-select v-model="queryParams.bankSide" placeholder="请选择岸别" clearable>
          <el-option
            v-for="dict in dict.type.ab"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="航标类型" prop="markType">
        <el-select v-model="queryParams.markType" placeholder="请选择航标类型" clearable>
          <el-option
            v-for="dict in dict.type.hb_type"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>

      <el-form-item label="标体颜色" prop="markColor">
        <el-select v-model="queryParams.markColor" placeholder="请选择标体颜色" clearable>
          <el-option
            v-for="dict in dict.type.btys"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>

      <el-form-item label="是否遥测遥控" prop="isRemoteMonitor">
        <el-select v-model="queryParams.isRemoteMonitor" placeholder="请选择是否遥测遥控" clearable>
          <el-option
            v-for="dict in dict.type.yesno"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['system:navigationMark:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['system:navigationMark:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['system:navigationMark:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['system:navigationMark:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="navigationMarkList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="航标名称" align="center" prop="markName" />
      <el-table-column label="所属航道" align="center" prop="channel" />
      <el-table-column label="岸别" align="center" prop="bankSide">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.ab" :value="scope.row.bankSide"/>
        </template>
      </el-table-column>
      <el-table-column label="航标类型" align="center" prop="markType">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.hb_type" :value="scope.row.markType"/>
        </template>
      </el-table-column>
      <el-table-column label="设地地点" align="center" prop="location" />
      <el-table-column label="管养单位" align="center" prop="managementUnit" />
      <el-table-column label="设置方式" align="center" prop="setupMethod">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.blcl" :value="scope.row.setupMethod"/>
        </template>
      </el-table-column>
      <el-table-column label="设标水深" align="center" prop="setupDepth" />
      <el-table-column label="安全距离" align="center" prop="safeDistance" />
      <el-table-column label="标体颜色" align="center" prop="markColor">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.btys" :value="scope.row.markColor"/>
        </template>
      </el-table-column>
      <el-table-column label="航标高度" align="center" prop="markHeight" />
      <el-table-column label="标体形状" align="center" prop="markShape" />
      <el-table-column label="标体材质" align="center" prop="markMaterial">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.blcl" :value="scope.row.markMaterial"/>
        </template>
      </el-table-column>
      <el-table-column label="航标纬度" align="center" prop="latitude" />
      <el-table-column label="航标经度" align="center" prop="longitude" />
      <el-table-column label="锚链长度" align="center" prop="chainLength" />
      <el-table-column label="是否发光" align="center" prop="isLuminous">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.yesno" :value="scope.row.isLuminous"/>
        </template>
      </el-table-column>
      <el-table-column label="是否遥测遥控" align="center" prop="isRemoteMonitor">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.yesno" :value="scope.row.isRemoteMonitor"/>
        </template>
      </el-table-column>
      <el-table-column label="仪器类型" align="center" prop="instrumentType" />
      <el-table-column label="灯光功率" align="center" prop="lightPower" />
      <el-table-column label="额定电压" align="center" prop="ratedVoltage" />
      <el-table-column label="透镜参数" align="center" prop="lens" />
      <el-table-column label="光色" align="center" prop="lightColor">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.btys" :value="scope.row.lightColor"/>
        </template>
      </el-table-column>
      <el-table-column label="闪光类型" align="center" prop="flashType">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.btys" :value="scope.row.flashType"/>
        </template>
      </el-table-column>
      <el-table-column label="灯光视距" align="center" prop="lightVisualRange" />
      <el-table-column label="航标识距" align="center" prop="markVisualRange" />
      <el-table-column label="灯光能源" align="center" prop="lightEnergySource" />
      <el-table-column label="电池类别" align="center" prop="batteryType">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.ab" :value="scope.row.batteryType"/>
        </template>
      </el-table-column>
      <el-table-column label="电池容量" align="center" prop="batteryCapacity" />
      <el-table-column label="设标时间" align="center" prop="setupTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.setupTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="最近改造时间" align="center" prop="latestModifyTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.latestModifyTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="遥测号码" align="center" prop="remoteMonitorNumber" />
      <el-table-column label="图片" align="center" prop="pic" width="100">
        <template slot-scope="scope">
          <image-preview :src="scope.row.pic" :width="50" :height="50"/>
        </template>
      </el-table-column>
      <el-table-column label="备注" align="center" prop="remark" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['system:navigationMark:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['system:navigationMark:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改航标基础信息对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="航标名称" prop="markName">
          <el-input v-model="form.markName" placeholder="请输入航标名称" />
        </el-form-item>
        <el-form-item label="所属航道" prop="channel">
          <el-input v-model="form.channel" placeholder="请输入所属航道" />
        </el-form-item>
        <el-form-item label="岸别" prop="bankSide">
          <el-select v-model="form.bankSide" placeholder="请选择岸别">
            <el-option
              v-for="dict in dict.type.ab"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="航标类型" prop="markType">
          <el-select v-model="form.markType" placeholder="请选择航标类型">
            <el-option
              v-for="dict in dict.type.hb_type"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="设地地点" prop="location">
          <el-input v-model="form.location" placeholder="请输入设地地点" />
        </el-form-item>
        <el-form-item label="管养单位" prop="managementUnit">
          <el-input v-model="form.managementUnit" placeholder="请输入管养单位" />
        </el-form-item>
        <el-form-item label="设置方式" prop="setupMethod">
          <el-select v-model="form.setupMethod" placeholder="请选择设置方式">
            <el-option
              v-for="dict in dict.type.blcl"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="设标水深" prop="setupDepth">
          <el-input v-model="form.setupDepth" placeholder="请输入设标水深" />
        </el-form-item>
        <el-form-item label="安全距离" prop="safeDistance">
          <el-input v-model="form.safeDistance" placeholder="请输入安全距离" />
        </el-form-item>
        <el-form-item label="标体颜色" prop="markColor">
          <el-select v-model="form.markColor" placeholder="请选择标体颜色">
            <el-option
              v-for="dict in dict.type.btys"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="航标高度" prop="markHeight">
          <el-input v-model="form.markHeight" placeholder="请输入航标高度" />
        </el-form-item>
        <el-form-item label="标体形状" prop="markShape">
          <el-input v-model="form.markShape" placeholder="请输入标体形状" />
        </el-form-item>
        <el-form-item label="标体材质" prop="markMaterial">
          <el-select v-model="form.markMaterial" placeholder="请选择标体材质">
            <el-option
              v-for="dict in dict.type.blcl"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="航标纬度" prop="latitude">
          <el-input v-model="form.latitude" placeholder="请输入航标纬度" />
        </el-form-item>
        <el-form-item label="航标经度" prop="longitude">
          <el-input v-model="form.longitude" placeholder="请输入航标经度" />
        </el-form-item>
        <el-form-item label="锚链长度" prop="chainLength">
          <el-input v-model="form.chainLength" placeholder="请输入锚链长度" />
        </el-form-item>
        <el-form-item label="是否发光" prop="isLuminous">
          <el-select v-model="form.isLuminous" placeholder="请选择是否发光">
            <el-option
              v-for="dict in dict.type.yesno"
              :key="dict.value"
              :label="dict.label"
              :value="parseInt(dict.value)"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="是否遥测遥控" prop="isRemoteMonitor">
          <el-select v-model="form.isRemoteMonitor" placeholder="请选择是否遥测遥控">
            <el-option
              v-for="dict in dict.type.yesno"
              :key="dict.value"
              :label="dict.label"
              :value="parseInt(dict.value)"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="灯光功率" prop="lightPower">
          <el-input v-model="form.lightPower" placeholder="请输入灯光功率" />
        </el-form-item>
        <el-form-item label="额定电压" prop="ratedVoltage">
          <el-input v-model="form.ratedVoltage" placeholder="请输入额定电压" />
        </el-form-item>
        <el-form-item label="透镜参数" prop="lens">
          <el-input v-model="form.lens" placeholder="请输入透镜参数" />
        </el-form-item>
        <el-form-item label="光色" prop="lightColor">
          <el-select v-model="form.lightColor" placeholder="请选择光色">
            <el-option
              v-for="dict in dict.type.btys"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="闪光类型" prop="flashType">
          <el-select v-model="form.flashType" placeholder="请选择闪光类型">
            <el-option
              v-for="dict in dict.type.btys"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="灯光视距" prop="lightVisualRange">
          <el-input v-model="form.lightVisualRange" placeholder="请输入灯光视距" />
        </el-form-item>
        <el-form-item label="航标识距" prop="markVisualRange">
          <el-input v-model="form.markVisualRange" placeholder="请输入航标识距" />
        </el-form-item>
        <el-form-item label="灯光能源" prop="lightEnergySource">
          <el-input v-model="form.lightEnergySource" placeholder="请输入灯光能源" />
        </el-form-item>
        <el-form-item label="电池类别" prop="batteryType">
          <el-select v-model="form.batteryType" placeholder="请选择电池类别">
            <el-option
              v-for="dict in dict.type.ab"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="电池容量" prop="batteryCapacity">
          <el-input v-model="form.batteryCapacity" placeholder="请输入电池容量" />
        </el-form-item>
        <el-form-item label="设标时间" prop="setupTime">
          <el-date-picker clearable
            v-model="form.setupTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择设标时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="最近改造时间" prop="latestModifyTime">
          <el-date-picker clearable
            v-model="form.latestModifyTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择最近改造时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="遥测号码" prop="remoteMonitorNumber">
          <el-input v-model="form.remoteMonitorNumber" placeholder="请输入遥测号码" />
        </el-form-item>
        <el-form-item label="图片" prop="pic">
          <image-upload v-model="form.pic"/>
        </el-form-item>
        <el-form-item label="备注" prop="remark">
          <el-input v-model="form.remark" placeholder="请输入备注" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listNavigationMark, getNavigationMark, delNavigationMark, addNavigationMark, updateNavigationMark } from "@/api/system/navigationMark"

export default {
  name: "NavigationMark",
  dicts: ['yesno', 'blcl', 'ab', 'btys', 'hb_type'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 航标基础信息表格数据
      navigationMarkList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        markName: null,
        channel: null,
        bankSide: null,
        markType: null,
        location: null,
        managementUnit: null,
        setupMethod: null,
        setupDepth: null,
        safeDistance: null,
        markColor: null,
        markHeight: null,
        markShape: null,
        markMaterial: null,
        latitude: null,
        longitude: null,
        chainLength: null,
        isLuminous: null,
        isRemoteMonitor: null,
        instrumentType: null,
        lightPower: null,
        ratedVoltage: null,
        lens: null,
        lightColor: null,
        flashType: null,
        lightVisualRange: null,
        markVisualRange: null,
        lightEnergySource: null,
        batteryType: null,
        batteryCapacity: null,
        setupTime: null,
        latestModifyTime: null,
        remoteMonitorNumber: null,
        pic: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        markName: [
          { required: true, message: "航标名称不能为空", trigger: "blur" }
        ],
      }
    }
  },
  created() {
    this.getList()
  },
  methods: {
    /** 查询航标基础信息列表 */
    getList() {
      this.loading = true
      listNavigationMark(this.queryParams).then(response => {
        this.navigationMarkList = response.rows
        this.total = response.total
        this.loading = false
      })
    },
    // 取消按钮
    cancel() {
      this.open = false
      this.reset()
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        markName: null,
        channel: null,
        bankSide: null,
        markType: null,
        location: null,
        managementUnit: null,
        setupMethod: null,
        setupDepth: null,
        safeDistance: null,
        markColor: null,
        markHeight: null,
        markShape: null,
        markMaterial: null,
        latitude: null,
        longitude: null,
        chainLength: null,
        isLuminous: null,
        isRemoteMonitor: null,
        instrumentType: null,
        lightPower: null,
        ratedVoltage: null,
        lens: null,
        lightColor: null,
        flashType: null,
        lightVisualRange: null,
        markVisualRange: null,
        lightEnergySource: null,
        batteryType: null,
        batteryCapacity: null,
        setupTime: null,
        latestModifyTime: null,
        remoteMonitorNumber: null,
        pic: null,
        remark: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null
      }
      this.resetForm("form")
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm")
      this.handleQuery()
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset()
      this.open = true
      this.title = "添加航标基础信息"
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset()
      const id = row.id || this.ids
      getNavigationMark(id).then(response => {
        this.form = response.data
        this.open = true
        this.title = "修改航标基础信息"
      })
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateNavigationMark(this.form).then(response => {
              this.$modal.msgSuccess("修改成功")
              this.open = false
              this.getList()
            })
          } else {
            addNavigationMark(this.form).then(response => {
              this.$modal.msgSuccess("新增成功")
              this.open = false
              this.getList()
            })
          }
        }
      })
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids
      this.$modal.confirm('是否确认删除航标基础信息编号为"' + ids + '"的数据项？').then(function() {
        return delNavigationMark(ids)
      }).then(() => {
        this.getList()
        this.$modal.msgSuccess("删除成功")
      }).catch(() => {})
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/navigationMark/export', {
        ...this.queryParams
      }, `navigationMark_${new Date().getTime()}.xlsx`)
    }
  }
}
</script>
